package com.goods.controller.business;

import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import com.goods.controller.business.service.SupplierService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "物资来源")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    SupplierService supplierService;

    /**
     * 来源列表
     * @param pageNum
     * @param pageSize
     * @param supplierVO
     * @return
     */
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                         @RequestParam Integer pageSize,
                                         SupplierVO supplierVO){
        return ResponseBean.success(supplierService.findSupplierList(pageNum,pageSize,supplierVO));
    }

    /**
     * 添加
     * @param supplierVO
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        return ResponseBean.success(supplierService.add(supplierVO));
    }

    /**
     * 编辑
     * @param id
     * @return
     */
    @GetMapping("/edit/{id}")
    public ResponseBean<SupplierVO> edit(@PathVariable Long id){
        SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    /**
     * 修改
     * @param id
     * @param supplierVO
     * @return
     */
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody @Validated SupplierVO supplierVO){
        supplierService.update(id,supplierVO);
        return ResponseBean.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }
}
